package com.hangzhou.xyj.manager;

import android.content.Context;

import com.hangzhou.xyj.model.ShareModel;

import java.util.HashMap;

import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.tencent.qzone.QZone;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;

/**
 * Created by yaohuix on 2016/4/27  16:00
 * <p/>
 * 说明：分享管理器
 */
public class ShareManager {
    private static final ShareManager instance = new ShareManager();

    private ShareManager() {
    }

    public static ShareManager getInstance() {
        return instance;
    }

    public void init(Context context) {
        ShareSDK.initSDK(context, "113a6a1c9f52f");//在sharesdk后台注册的应用的appkey
        configShareParam();
    }

    /**
     * 设置分享的配置
     *
     * @param
     * @return
     * @author yaohuix
     * @date 2016/5/5 16:00
     */
    private void configShareParam() {
        ShareModel QQShareModel = new ShareModel("1105235409", "dO5NDfdF9q2bqunI", 0, true, 4, true);
        ShareModel WeChatShareModel = new ShareModel("wx412f7cd24b11b1d5", "d9faba0ee012f406b3cfea030976a40d", false, 2, 1, true);
        ShareModel WeChatMomentShareModel = new ShareModel("wx412f7cd24b11b1d5", "d9faba0ee012f406b3cfea030976a40d", false, 3, 2, true);
        ShareModel QZoneShareModel = new ShareModel("100371282", "aed9b0303e3ed1e27bae87c33761161d", 3, true, 1, true);
//        ShareModel SinaWeiboShareModel = new ShareModel("2861473711", "c6e4b934195c9e0c41549ef6452ea352", "www.baidu.com", false, 1, 1, false);
        ShareManager.getInstance().setQQShareConfig(QQShareModel);
//        ShareManager.getInstance().setSinaWeiboConfig(SinaWeiboShareModel);
        ShareManager.getInstance().setWechatConfig(WeChatShareModel);
        ShareManager.getInstance().setWechatMomentsConfig(WeChatMomentShareModel);
        ShareManager.getInstance().setQZoneConfig(QZoneShareModel);
    }

    /**
     * 设置QQ分享的配置
     *
     * @param model
     */
    public void setQQShareConfig(ShareModel model) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("Id", model.getId());
        hashMap.put("SortId", model.getSortId());
        hashMap.put("AppId", model.getAppId());
        hashMap.put("AppKey", model.getAppKey());
        hashMap.put("RedirectUrl", model.getRedirectUrl());
        hashMap.put("ShareByAppClient", model.isShareByAppClient());
        hashMap.put("Enable", model.isEnable());
        ShareSDK.setPlatformDevInfo(QQ.NAME, hashMap);
    }

    /**
     * 设置微信-朋友圈分享的配置
     *
     * @param
     * @return
     * @author yaohuix
     * @date 2016/4/27 16:20
     */
    public void setWechatMomentsConfig(ShareModel model) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("Id", model.getId());
        hashMap.put("SortId", model.getSortId());
        hashMap.put("AppId", model.getAppId());
        hashMap.put("AppSecret", model.getAppSecret());
        hashMap.put("Enable", model.isEnable());
        hashMap.put("BypassApproval", model.isBypassApproval());
        ShareSDK.setPlatformDevInfo(WechatMoments.NAME, hashMap);
    }

    /**
     * 设置微信分享的配置
     *
     * @param
     * @return
     * @author yaohuix
     * @date 2016/4/27 16:20
     */
    public void setWechatConfig(ShareModel model) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("Id", model.getId());
        hashMap.put("SortId", model.getSortId());
        hashMap.put("AppId", model.getAppId());
        hashMap.put("AppSecret", model.getAppSecret());
        hashMap.put("Enable", model.isEnable());
        hashMap.put("BypassApproval", model.isBypassApproval());
        ShareSDK.setPlatformDevInfo(Wechat.NAME, hashMap);
    }

    /**
     * 设置QQ空间分享的配置
     *
     * @param
     * @return
     * @author yaohuix
     * @date 2016/4/27 16:26
     */
    public void setQZoneConfig(ShareModel model) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("Id", model.getId());
        hashMap.put("SortId", model.getSortId());
        hashMap.put("AppId", model.getAppId());
        hashMap.put("AppKey", model.getAppKey());
        hashMap.put("Enable", model.isEnable());
        hashMap.put("ShareByAppClient", model.isShareByAppClient());
        ShareSDK.setPlatformDevInfo(QZone.NAME, hashMap);
    }

    /**
     * 设置微博分享的配置
     *
     * @param
     * @return
     * @author yaohuix
     * @date 2016/4/27 16:28
     */
    public void setSinaWeiboConfig(ShareModel model) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("Id", model.getId());
        hashMap.put("SortId", model.getSortId());
        hashMap.put("AppSecret", model.getAppSecret());
        hashMap.put("AppKey", model.getAppKey());
        hashMap.put("RedirectUrl", model.getRedirectUrl());
        hashMap.put("Enable", model.isEnable());
        ShareSDK.setPlatformDevInfo(QZone.NAME, hashMap);
    }
}
